//
// Created by Administrator on 2022/11/2.
//

#include <iostream>
#include "arrUtil.h"
using namespace std;

void shell(int a[], int l);

int main()
{
//    int arr[] = {9,8,7,5,6,4,3,2,1,0};
    int arr[10];
    int len = 10;
    randomArr(arr,len);
    shell(arr,len);
    printArr(arr,len);
    return 0;
}

void shell(int a[], int l)
{
    int gap = l/2;
    while(gap>0)
    {
        for (int i = 0; i < l-gap; i+=gap)
        {
            int j = i;
            int cur = a[j+gap];
            while(j>=0 and a[j]>cur)
            {
                a[j+gap]=a[j];
//                printf("cur=%d\n",cur);
                j-=gap;
            }
            a[j+gap]=cur;
//            printf("gap=%d, %d ",gap,a[i]);
        }
        gap/=2;
    }
}
